Skip to content

bpo-29569: threading.Timer class: Continue periodical execution till action return True#191

Closed
slytomcat wants to merge 1 commit intopython:masterfrom
slytomcat:Periodical.Timer
Closed

bpo-29569: threading.Timer class: Continue periodical execution till action return True#191
slytomcat wants to merge 1 commit intopython:masterfrom
slytomcat:Periodical.Timer

Conversation

@slytomcat
Copy link

I think that functionality of threading.Timer class can be easily extended to generate the sequence of runs with specified period. The idea comes from the GLib.timeout_add function.

http://bugs.python.org/issue29569

As most current CB functions that are used in Timer returns nothing (None) they will run only once as earlier. Only functions that returns True will continue their periodical execution.

There are two ways to stop such continues execution:

  • Return something that is not True from action function,
  • Call cancel method of Timer class.

Changed method run should look like:

    def run(self):
        """Continue execution after wait till function returns True"""
        while(not self.finished.wait(self.interval)):
            if not self.function(*self.args, **self.kwargs):
                break
        self.finished.set()

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants